#ifndef ALTMATH_EXPRESSIONTREENODE_H
#define ALTMATH_EXPRESSIONTREENODE_H

#include <QSharedPointer>
#include <QString>
#include "globals.h"

namespace AltMath {
     /*! Base class for mathematical entities. Constants, variables, operators, functions, etc. */
     class ExpressionTreeNode {
     public:
          /*! Pointer to an expression tree node. */
          typedef QSharedPointer<ExpressionTreeNode> Pointer;

          /*! The result of an operation. */
          struct Result {
               /*! The value of the operation. */
               Real value;
               /*! Whether the operation was successful. */
               bool success;
               /*! Any error or warning messages regarding the operation. */
               QString message;
               /*! Constructor
                    @param v The value of the operation.
                    @param s Whether the operation was successful.
                    @param m Any error or warning messages. */
               Result(Real v = 0.0, bool s = true, QString m = ""){
                    value = v;
                    success = s;
                    message = m;
               }
          };

          /*! Evaluates the node.  */
          virtual Result evaluate() const = 0;

          /*! The left child. */
          const Pointer& left() const;
          /*! The right child. */
          const Pointer& right() const;

          /*! Sets the left child.
               @param newLeft The new left child. */
          void setLeft(const Pointer& newLeft);
          /*! Sets the right child.
               @param newRight The new right child. */
          void setRight(const Pointer& newRight);

     private:
          /*! Left child. */
          Pointer m_left;
          /*! Right child. */
          Pointer m_right;
     };

     /*! Pointer to an expression tree node. */
}

#endif
